#include <stdio.h>
#include <getopt.h>

int main(int argc, char* argv[])
{
    int c = 0;
    int option_index;

    struct option long_options[] = {
        {"add",     required_argument, 0, 'a'}, 
        {"delete",  required_argument, 0, 'd'},
        {"clear",   required_argument, 0, 'c'},
        {"list",    required_argument, 0, 'l'},
        {0,         0,                 0,      0 }
    };

    while (1) {
        int c = getopt_long(argc, argv, "a:d:cl::", long_options, &option_index);
        if (c == -1)
            break;

        printf("c = %c, optopt = %c, optarg = %s\n", c, optopt, optarg);
    }

    if (optind < argc) {
        printf("parameters:\n");
        while (optind < argc) {
            printf("%s\n", argv[optind++]);
        }
    }

    return 0;
}
